package com.boot.api;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class ApiResult<T> {

    private int code;
    private String message;
    private T data;

    public ApiResult<T> setCode(ApiCode apiCode) {
        this.code = apiCode.getCode();
        return this;
    }

    public ApiResult<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public ApiResult<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <T> ApiResult<T> success(){
        return new ApiResult<T>().setCode(ApiCode.SUCCESS).setMessage(ApiCode.SUCCESS.getMsg());
    }

    public static <T> ApiResult<T> success(String msg){
        return new ApiResult<T>().setCode(ApiCode.SUCCESS).setMessage(msg);
    }

    public static <T> ApiResult<T> success(T data){
        return new ApiResult<T>().setCode(ApiCode.SUCCESS).setMessage(ApiCode.SUCCESS.getMsg()).setData(data);
    }

    public static <T> ApiResult<T> success(String msg, T data){
        return new ApiResult<T>().setCode(ApiCode.SUCCESS).setMessage(msg).setData(data);
    }

    public static <T> ApiResult<T> failed() {
        return new ApiResult<T>().setCode(ApiCode.FAILED).setMessage(ApiCode.FAILED.getMsg());
    }

    public static <T> ApiResult<T> failed(String msg) {
        return new ApiResult<T>().setCode(ApiCode.FAILED).setMessage(msg);
    }

    public static <T> ApiResult<T> unAuthentication() {
        return new ApiResult<T>().setCode(ApiCode.UN_AUTHENTICATION).setMessage(ApiCode.UN_AUTHENTICATION.getMsg());
    }

}
